package com.qingke.jdbc.connection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;

public class JdbcBatch {

	public static void main(String[] args) {
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		
		try {
			conn = MyJdbcConnection.getConnection();
			stmt = conn.prepareStatement("insert into qingke.aaa(`id`, `year`, `month`, `amount`) values(?, ?, ?, ?)");
			
			for (int index = 1; index <= 4; index++) {
				stmt.setInt(1, index + 8);
				stmt.setString(2, "1993");
				stmt.setString(3, index + "");
				stmt.setString(4, "3." + index);
				
				stmt.addBatch();
			}
			
			int[] result = stmt.executeBatch();
			
			System.out.println("result: " + Arrays.toString(result));
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			MyJdbcConnection.clean(conn, stmt, rs);
		}
		
	}

}
